package com.yumis.service.modules.car.controller;

import com.yumis.service.common.enums.HttpState;
import com.yumis.service.common.vo.Response;
import com.yumis.service.model.pojo.Car;
import com.yumis.service.model.pojo.CarTaskTime;
import com.yumis.service.modules.car.service.CarTaskTimeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("cartasktime")
public class CarTaskTimeController {
    @Autowired
    private CarTaskTimeService carTaskTimeService;

    /**
     * 新增
     * @param carTaskTime
     * @return
     */
    @PostMapping("addCarTaskTime")
    public ResponseEntity<Response> addCarTaskTime(@Valid CarTaskTime carTaskTime){
        carTaskTimeService.addCarTaskTime(carTaskTime);
        return ResponseEntity.ok().body(Response.buildResponse(HttpState.OK));
    }

    /**
     * 根据id删除
     * @param id
     * @return
     */
    @PostMapping("deleteCarTaskTimeById")
    public ResponseEntity<Response> deleteCarTaskTimeById(@RequestParam("id") Long id){
        carTaskTimeService.deleteCarTaskTimeById(id);
        return ResponseEntity.ok().body(Response.buildResponse(HttpState.OK));
    }
    /**
     * 根据用户id查询车辆信息
     * @param id
     * @return
     */
    @PostMapping("queryTaskTimeById")
    public ResponseEntity<Response> queryTaskTimeById(@RequestParam("id") Long id){
        return ResponseEntity.ok().body(Response.buildResponse(HttpState.OK,carTaskTimeService.queryTaskTimeById(id)));
    }

    /**
     * 修改
     * @param carTaskTime
     * @return
     */
    @PostMapping("updateTaskTime")
    public ResponseEntity<Response> updateTaskTime(@Valid CarTaskTime carTaskTime){
        carTaskTimeService.updateTaskTime(carTaskTime);
        return ResponseEntity.ok().body(Response.buildResponse(HttpState.OK));
    }
}
